<template>
  <div>
    <el-table
      :data="tableData"
      v-loading="loading"
      stripe
      style="width: 100%"
      max-height="600"
    >
      <el-table-column prop="schoolName" label="校区" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="semesterName" label="学期" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="gradeName" label="年级" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="className" label="班级" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="majorsName" label="专业" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="directionName" label="方向" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间" width="180">
      </el-table-column>
      <el-table-column label="操作" width="140">
        <template slot-scope="{ row }">
          <el-button-group>
            <el-button
              type="primary"
              size="mini"
              @click="handleEdit(row)"
              :disabled="$button('800') == false ? true : false"
              >编辑</el-button
            >
            <el-button
              type="danger"
              size="mini"
              @click="handleDelete(row)"
              :disabled="$button('801') == false ? true : false"
              >删除</el-button
            >
          </el-button-group>
        </template>
      </el-table-column>
      <div slot="empty" class="emptyBg">
        <el-empty :image-size="200"></el-empty>
      </div>
    </el-table>
    <Pagination
      v-show="parseInt(pageObj.count) > 0"
      :total="parseInt(pageObj.count)"
      @change="getList"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
    />
  </div>
</template>
<script>
import {
  eduTeachingQuery,
  eduTeachingDelete,
} from '@/api/admin/teach/eduTeaching.js'
import Bus from '@/utils/bus.js'
export default {
  data() {
    return {
      loading: false,
      listQuery: {
        page: 1,
        limit: 10,
        type: this.type,
      },
      tableData: [],
      pageObj: {},
    }
  },
  props: ['type'],
  mounted() {
    this.getList()
    Bus.$on('refreshTeachingClassList', (v) => {
      if (v) {
        Object.assign(this.listQuery, v)
      }
      this.getList()
    })
  },
  beforeDestroy() {
    Bus.$off('refreshTeachingClassList')
  },
  methods: {
    getList() {
      this.loading = true
      eduTeachingQuery(this.listQuery).then((res) => {
        setTimeout(() => {
          this.tableData = res.data.data
          this.pageObj = res.data
          this.loading = false
        }, 200)
      })
    },
    //编辑
    handleEdit(row) {
      Bus.$emit('showDialogTeachingClassAdd', row)
    },
    //删除确认
    handleDelete(row) {
      this.$confirm('确定要删除吗?', '提示', {
        confirmButtonText: '删除',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.delete(row)
        })
        .catch(() => {})
    },
    //删除
    delete(row) {
      eduTeachingDelete(row.id).then((res) => {
        this.getList()
        this.$message({
          message: '操作成功',
          type: 'success',
        })
      })
    },
  },
}
</script>